package cn.luischen.controller.admin;

import org.slf4j.LoggerFactory;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import cn.luischen.controller.BaseController;
import io.swagger.annotations.ApiOperation;
import cn.luischen.dto.cond.CommentCond;
import cn.luischen.model.CommentDomain;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import cn.luischen.model.UserDomain;
import org.springframework.stereotype.Controller;
import cn.luischen.service.comment.CommentService;
import javax.servlet.http.HttpServletRequest;
import cn.luischen.utils.APIResponse;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import cn.luischen.exception.BusinessException;
import cn.luischen.constant.ErrorConstant;

import static org.junit.Assert.fail;
import org.mockito.MockitoAnnotations;
import org.junit.After;
import java.util.Map;
import java.lang.reflect.Method;
import static org.junit.Assert.*;
import java.util.List;
import com.alibaba.fastjson.TypeReference;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.powermock.reflect.Whitebox;
import org.mockito.Mock;
import org.junit.runner.RunWith;
import java.util.HashMap;
import java.util.ArrayList;
import com.alibaba.fastjson.JSONArray;
import org.powermock.core.classloader.annotations.PrepareForTest;
import static org.junit.Assert.assertEquals;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.junit.rules.ExpectedException;
import org.mockito.InjectMocks;
import org.junit.Test;
import com.unitspirit.runtime.*;
import org.mockito.Mockito;
import com.alibaba.fastjson.JSON;
import org.junit.Rule;
import static org.junit.Assert.assertTrue;
import com.alibaba.fastjson.parser.ParserConfig;

/**
* The class <code>CommentControllerTest</code> contains tests for the class <code>{@link CommentController}</code>.
* Copyright (c) 2020
* 
* @generatedBy UnitSpirit at 2021-09-07 17:51:36
* @version 1.0.20210903
*/

@PowerMockIgnore({ "javax.management.*" })
@RunWith(PowerMockRunner.class)
@PrepareForTest({ cn.luischen.dto.cond.CommentCond.class })
public class CommentController_index_WGTest {

	@InjectMocks
	cn.luischen.controller.admin.CommentController unitspirit_fixture;
	@Mock
	cn.luischen.service.comment.CommentService mock_CommentService;

	@Rule
	public ExpectedException unitspirit_thrown = ExpectedException.none();

	/**
	* 测试方法初始化.
	* 
	* @throws Exception 
	*         if the initialization fails for some reason 
	*  
	* @generatedBy UnitSpirit at 2021-09-07 17:51:36
	*/
	@org.junit.Before
	public void setUp() throws Exception {
		try {
			GlobalUnitInit.init();
			MockitoAnnotations.initMocks(this);
			ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	/**
	* @date 2021-09-07 17:51:36
	* @see cn.luischen.controller.admin.CommentController#index
	* @category auto generate by UnitSpirit  
	* @author UnitSpirit   
	*/
	@Test
	public void test_index_20210331_175301_101_2_01() throws Throwable {
		unitspirit_fixture = PowerMockito.spy(unitspirit_fixture);
		//被测函数参数定义
		int int_p_0 = 1;
		int int_p_1 = 15;
		javax.servlet.http.HttpServletRequest HttpServletRequest_p_2 = Mockito
				.mock(javax.servlet.http.HttpServletRequest.class);
		//成员变量设置

		//返回值定义 
		String result_expected = "\"admin/comment_list\"";

		cn.luischen.model.UserDomain mock_result_UserDomain3 = JSON.parseObject(
				"{\"activated\":0,\"created\":1490756162,\"email\":\"1034683568@qq.com\",\"groupName\":\"visitor\",\"logged\":0,\"password\":\"a66abb5684c45962d887564f08346e8d\",\"screenName\":\"admin\",\"uid\":1,\"username\":\"admin\"}",
				cn.luischen.model.UserDomain.class);
		PowerMockito.doReturn(mock_result_UserDomain3).when(unitspirit_fixture).user(Mockito.any());
		cn.luischen.dto.cond.CommentCond mock_sub_caller_CommentCond2 = PowerMockito
				.mock(cn.luischen.dto.cond.CommentCond.class);
		com.github.pagehelper.PageInfo mock_result_PageInfo1 = JSON.parseObject(
				"{\"endRow\":0,\"hasNextPage\":false,\"hasPreviousPage\":false,\"isFirstPage\":false,\"isLastPage\":true,\"list\":[],\"navigateFirstPage\":0,\"navigateLastPage\":0,\"navigatePages\":8,\"navigatepageNums\":[],\"nextPage\":0,\"pageNum\":0,\"pageSize\":15,\"pages\":0,\"prePage\":0,\"size\":0,\"startRow\":0,\"total\":0}",
				com.github.pagehelper.PageInfo.class);

		PowerMockito.whenNew(cn.luischen.dto.cond.CommentCond.class).withNoArguments()
				.thenReturn(mock_sub_caller_CommentCond2);
		PowerMockito.when(mock_CommentService.getCommentsByCond(Mockito.any(), Mockito.anyInt(), Mockito.anyInt()))
				.thenReturn(mock_result_PageInfo1);

		String unitspirit_result = unitspirit_fixture.index(int_p_0, int_p_1, HttpServletRequest_p_2);
		//getAssertCase 
		UnitAssert.assertEquals(result_expected, unitspirit_result);
	}
}
